#ifndef CONSTRUCTOR_JS
#define CONSTRUCTOR_JS

#include "Concept.js"
#include "Patterns.js"

/* class */ Constructor = function(/* Concept */ concept)
{
	if (!(concept instanceof Concept))
	{
		throw "ArgumentException";
	}
	
	var _isStatic;
	var _signature;
	var _body;
	
	(function()
	{
		var captures = Constructor.GetRegExp(Patterns.Identifier).exec(concept.Head);
		
		if (captures == null)
		{
			throw "BadConceptException";
		}
		
		_signature = captures[Constructor.SignaturePosition + 1];
		_isStatic = (captures[Constructor.AccessModifierPosition] == "static");
		
		if (_isStatic && _signature != undefined)
		{
			throw "A static constructor cannot have a non-void signature.";
		}
		
		if (_signature == undefined)
		{
			_signature = "";
		}
		
		_body = concept.Body;
	})();
	
	this.__defineGetter__("IsStatic", function() { return _isStatic; });
	this.__defineSetter__("IsStatic", function() { throw "MethodAccessibilityException"; });
	
	this.__defineGetter__("Signature", function() { return _signature; });
	this.__defineSetter__("Signature", function() { throw "MethodAccessibilityException"; });
	
	this.__defineGetter__("Body", function() { return _body; });
	this.__defineSetter__("Body", function() { throw "MethodAccessibilityException"; });
};

/* static bool */ Constructor.IsMatching = function(/* string */ className, /* Concept */ concept)
{
	if (!(concept instanceof Concept))
	{
		throw "ArgumentException";
	}
	
	return Constructor.GetRegExp(className).test(concept.Head);
};

(function()
{
	var _patternStart = "^(public|static)[ ]";
	var _patternEnd = "\\(" + Patterns.Signature + "\\)$";
	
	Constructor.GetRegExp = function(/* string */ className)
	{
		return new RegExp(_patternStart + className + _patternEnd);
	}
	
	var _accessModifierPosition = 1;
	Constructor.__defineGetter__("AccessModifierPosition", function() { return _accessModifierPosition; });
	Constructor.__defineSetter__("AccessModifierPosition", function() { throw "MethodAccessibilityException"; });
	
	var _signaturePosition = 2;
	Constructor.__defineGetter__("SignaturePosition", function() { return _signaturePosition; });
	Constructor.__defineSetter__("SignaturePosition", function() { throw "MethodAccessibilityException"; });
})();

#endif
